import { fileURLToPath, URL } from 'node:url';

import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import VueDevTools from 'vite-plugin-vue-devtools';
// import styleImport, { VantResolve } from 'vite-plugin-style-import';

export default defineConfig(({ mode }) => {
    const env = loadEnv(mode, process.cwd());
    const { VITE_PROXY_URL, VITE_BASE_PATH } = env;
    return {
        plugins: [vue(), vueJsx(), VueDevTools()],
        base: VITE_BASE_PATH,
        publicPath: './',
        outputDir: 'dist',
        resolve: {
            alias: {
                '@': fileURLToPath(new URL('./src', import.meta.url))
            }
        },
        server: {
            proxy: {
                '/api': {
                    target: VITE_PROXY_URL,
                    changeOrigin: true,
                    rewrite: (path: string) => {
                        return path.replace(/^\/api/, '');
                    }
                }
            }
        },
    };
});
